package com.warm.androidstudy.utils;

import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.ArrayMap;


import com.warm.androidstudy.constant.SType;

import java.io.Serializable;


/**
 * Created by admin on 2016/8/3.
 * 私有的Intent页面跳转的工具
 */
public class MyIntentUtil {
    /**
     * 传参的跳转.私有静态方法
     *
     * @param cls：对应Activity
     * @param arrayMap:只能String，Serializable，Parcelable
     */
    private static void paraIntent(Context context, Class<?> cls, ArrayMap<String, Object> arrayMap) {
        Intent intent = new Intent(context, cls);
        if (arrayMap != null && arrayMap.size() > 0) {
            for (int i = 0; i < arrayMap.size(); i++) {
                String curKey = arrayMap.keyAt(i);
                Object curValue = arrayMap.valueAt(i);
                if (!TextUtils.isEmpty(curKey) && curValue != null) {
                    if (curValue instanceof String)
                        intent.putExtra(curKey, (String) curValue);
                    else if (curValue instanceof Serializable)
                        intent.putExtra(curKey, (Serializable) curValue);
                    else if (curValue instanceof Parcelable)
                        intent.putExtra(curKey, (Parcelable) curValue);
                }
            }
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }


    //跳转到Web页（首次默认显示标题栏，web页要顶下去）
    public static void WebActivity(Context context, String url, boolean isShowToolBar) {
        ArrayMap<String, Object> arrayMap = new ArrayMap<>();
        arrayMap.put(SType.Intent_URl, url);//网址
        arrayMap.put("isShowToolBar", isShowToolBar);
//        paraIntent(context, WebOutShowBarActivity.class, arrayMap);
    }

}
